﻿using GenericHtml;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using WLFramework.Json;
using WLFramework.Web;

namespace SampleSite.admin.ajax
{
    /// <summary>
    /// getPositions 的摘要说明
    /// </summary>
    public class getPositions : AjaxHttpHandler
    {
        public override void OnProcessRequest(HttpContext context)
        {
            int page = context.GetValueByName<int>("page");
            int rows = context.GetValueByName<int>("rows");

            using (var db = new PermissionContext())
            {
                var positions = db.View_Positions.Where(k => k.P_State != 2);

                context.Response.Write(JSON.Instance.ToJSON(new
                {
                    total = positions.Count(),
                    rows = positions.Skip((page - 1) * rows).Take(rows)
                    .Select(k => new
                    {
                        P_ID = k.P_ID,
                        P_Org = k.P_Org,
                        P_Level = k.P_Level,
                        P_State = k.P_State,
                        state = k.P_State,
                        P_CName = k.P_CName,
                        P_EName = k.P_EName,
                        O_CName = k.O_CName
                    }).ToList()
                }));
            }
        }
    }
}